package dryven.unittest;

import dryven.discovery.ClassDiscovery;
import dryven.discovery.ClassDiscoveryAdapter;
import dryven.discovery.ClassDiscoveryListener;
import dryven.discovery.DiscoveryConsumer;
import dryven.discovery.annotation.Annotation;
import dryven.reflection.TypeRef;
import dryven.util.ClassPathIterable;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

public class AllTests {

	public static Test suite() {
		String packageName = AllTests.class.getPackage().getName();
		final TestSuite suite = new TestSuite("Tests for "+packageName);
		
		ClassDiscovery cd = new ClassDiscovery(new String[]{packageName}, new ClassPathIterable());
		cd.addListener(new ClassDiscoveryAdapter() {
					@Override
					public void onClass(String typeName, String superClassName,
							String[] interfaces) {
						if(superClassName.equals(TestCase.class.getName())) {
							try {
								suite.addTestSuite(Class.forName(typeName));
							} catch (ClassNotFoundException e) {
								e.printStackTrace();
							}
						}
					}
			});
		cd.scan();
		return suite;
	}

}
